import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: 'Dashboard',
      component: () => import('@/views/dashboard/index'),
      meta: { title: '系统首页', icon: 'el-icon-loading' }
    }]
  },

  {
    path: '/example',
    component: Layout,
    redirect: '/example/table',
    name: 'Example',
    meta: { title: '用户操作', icon: 'el-icon-setting' },
    children: [
      {
        path: 'table',
        name: 'Table',
        component: () => import('@/views/table/index'),
        meta: { title: '用户展示', icon: 'el-icon-s-data' }
      },
      {
        path: 'addUser',
        name: 'AddUser',
        component: () => import('@/views/addUser/index'),
        meta: { title: '新增用户', icon: 'el-icon-circle-plus' }
      },
      {
        path: 'extras',
        name: 'Extras',
        component: () => import('@/views/extras/index'),
        meta: { title: '附件管理', icon: 'el-icon-picture' }
      },
      {
        path: 'power',
        name: 'Power',
        component: () => import('@/views/power/index'),
        meta: { title: '权限管理', icon: 'el-icon-folder' }
      },
      {
        path: 'department',
        name: 'Department',
        component: () => import('@/views/department/index'),
        meta: { title: '部门管理', icon: 'el-icon-s-home' }
      },
      {
        path: 'role',
        name: 'Role',
        component: () => import('@/views/role/index'),
        meta: { title: '角色管理', icon: 'el-icon-postcard' }
      },
      {
        path: 'notice',
        name: 'Notice',
        component: () => import('@/views/notice/index'),
        meta: { title: '公告管理', icon: 'el-icon-edit-outline' },
      },
    ]
  },


  {
    path: '/form',
    component: Layout,
    meta: {
      title: '业务管理',
      icon: 'el-icon-suitcase'
    },
    children: [
      {
        path: 'materials',
        name: 'Materials',
        component: () => import('@/views/materials/index'),
        meta: { title: '物资入库', icon: 'el-icon-medal' }
      },
      {
        path: 'mat-management',
        name: 'Mat-management',
        component: () => import('@/views/mat-management/index'),
        meta: { title: '物资管理',icon:'el-icon-mouse'},
        children:[
          {
            path: 'record',
            name: 'Record',
            component: () => import('@/views/mat-management/record/index'),
            meta: { title: '入库记录', icon: 'el-icon-postcard' }
          },
          {
            path: 'material',
            name: 'Material',
            component: () => import('@/views/mat-management/material/index'),
            meta: { title: '物资资料', icon: 'el-icon-notebook-2' }
          },
          {
            path: 'outstock',
            name: 'Outstock',
            component: () => import('@/views/mat-management/outstock/index'),
            meta: { title: '发放记录', icon: 'el-icon-s-goods' }
          }
        ]
      }
    ]
  },

  {
    path: '/nested',
    component: Layout,
    redirect: '/nested/menu1',
    name: 'Nested',
    meta: {
        title: '日志管理',
      icon: 'nested'
    },
    children: [
      {
        path: 'log',
        component: () => import('@/views/nested/log/index'), // Parent router-view
        name: 'Log',
        meta: { title: '登录日志' },
      },
      {
        path: 'operationLog',
        component: () => import('@/views/nested/operationLog/index'),
        name: 'OperationLog',
        meta: { title: '操作日志' }
      }
    ]
  },// 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true },

  {
    path: '/fine',
    component: Layout,
    meta: {
      title: '员工健康',
      icon: 'el-icon-apple'
    },
    children: [
      {
        path: '/rumor',
        component: () =>import('@/views/fine/rumor/index'),
        name: 'rumor',
        meta: {
          title: '疫情辟谣',
          icon: 'el-icon-bangzhu'
        }
      },
      {
        path: '/yiqinStatus',
        component: () =>import('@/views/fine/yiqinStatus/index'),
        name: 'yiqinStatus',
        meta: {
          title: '全国疫情',
          icon: 'el-icon-stopwatch'
        }
      }
    ]
  },

  {
    path: '/map',
    component: Layout,
    meta: {
      title: '实时地图',
      icon: 'el-icon-location'
    },
    children: [
      {
        path: 'mapOne',
        component: () => import('@/views/map/mapOne/index'),
        name: 'mapOne',
        meta: {title: '全球航空路线图'}
      },
      {
        path: 'mapTwo',
        component: ()=> import('@/views/map/mapTwo/index'),
        name: 'mapTwo',
        meta: {title: '飞行详细路线'}
      }
    ]
  }
]


const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
